package com.shenghuai.bclient.stores.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup

@Suppress("ConvertSecondaryConstructorToPrimary")
class ListSimpleTypesAdapter<T> : ListSimpleAdapter<T> {

    private val layoutIdWithViewTypeUnit: (Function1<Int, Int>)
    private val itemViewTypeGet: (Function1<Int, Int>)

    constructor(
        ctx: Context,
        data: List<T>,
        layoutIdWithViewTypeUnit: (Function1<Int, Int>),
        itemViewTypeGet: (Function1<Int, Int>)
    ) : super(ctx, data, -1) {
        this.layoutIdWithViewTypeUnit = layoutIdWithViewTypeUnit
        this.itemViewTypeGet = itemViewTypeGet
    }

    override fun getItemViewType(position: Int): Int {
        return itemViewTypeGet.invoke(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val layoutId = layoutIdWithViewTypeUnit.invoke(viewType)
        val rootView = LayoutInflater.from(parent.context).inflate(layoutId, parent, false)
        val holder = ViewHolder(rootView)
        itemCreateCallback?.invoke(holder, viewType)
        return holder
    }

}